//
//  ZCOrderCheckLeftAndRightCell.m
//  ZCJZ
//
//  Created by sujeking on 2019/2/27.
//  Copyright © 2019年 jeking. All rights reserved.
//

#import "ZCOrderCheckLeftAndRightCell.h"
#import <Masonry.h>
#import <Toast.h>
#import <BlocksKit+UIKit.h>
#import "generalToolBox.h"
@interface ZCOrderCheckLeftAndRightCell()

@property (weak, nonatomic) IBOutlet UILabel *llabel;
@property (weak, nonatomic) IBOutlet UILabel *rlabel;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *rrc;



@end


@implementation ZCOrderCheckLeftAndRightCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
}

- (void)setFrame:(CGRect)frame{
    frame.origin.x += 10;
//    frame.origin.y += 10;
//    frame.size.height -= 10;
    frame.size.width -= 20;
    [super setFrame:frame];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

- (void)setKeystr:(NSString *)keystr {
    _keystr = keystr;
    self.llabel.text = keystr;
}

- (void)setValuestr:(NSString *)valuestr {
    _valuestr = valuestr;
    if (self.canMore) {
        self.rlabel.font = [UIFont fontWithName:@"iconfont" size:12];
//        valuestr = [valuestr stringByAppendingString:@"\U0000e64a"];
        self.rlabel.text = valuestr;
    } else {
        self.rlabel.text = valuestr;
    }
}

- (void)setCanCopy:(BOOL)canCopy {
    _canCopy = canCopy;
    if (canCopy) {
        UIButton *on = [self getcopyBtn];
        on.tag = 20;
        [self.contentView addSubview:on];
        [on mas_makeConstraints:^(MASConstraintMaker *make) {
            make.width.mas_equalTo(40);
            make.height.mas_equalTo(18);
            make.right.mas_equalTo(-12);
            make.centerY.mas_equalTo(self.rlabel);
        }];
        
        [on bk_addEventHandler:^(id sender) {
            UIPasteboard *past = [UIPasteboard generalPasteboard];
            past.string = self.valuestr;
            UIWindow *window = [UIApplication sharedApplication].keyWindow;
            [window makeToast:@"复制成功" duration:2.0 position:CSToastPositionCenter];
        } forControlEvents:UIControlEventTouchUpInside];

        self.rrc.constant = 60;
    } else {
        UIButton *on = [self.contentView viewWithTag:20];
        [on removeFromSuperview];
        self.rrc.constant = 12;
    }
}

- (UIButton *)getcopyBtn {
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.titleLabel.font = [UIFont systemFontOfSize:12];
    [btn setTitleColor:[generalToolBox getColorWithHexadecimalColorStr:@"0x666666"] forState:UIControlStateNormal];
    btn.layer.borderWidth = 0.5f;
    btn.layer.borderColor = [generalToolBox getColorWithHexadecimalColorStr:@"0x666666"].CGColor;
    [btn setTitle:@"复制" forState:UIControlStateNormal];
    return btn;
}

- (void)setValue_color:(UIColor *)value_color {
    _value_color = value_color;
    self.rlabel.textColor = value_color;
}


- (void)setCanMore:(BOOL)canMore {
    _canMore = canMore;
    if (canMore) {
        self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    } else {
        self.accessoryType = UITableViewCellAccessoryNone;
    }
    
}

@end
